SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE VIEW dbo.[DnnProduct_vw_DesktopModulePermissions]
AS
    SELECT     
	    PP.DesktopModulePermissionID, 
	    PP.PortalDesktopModuleID, 
	    P.PermissionID, 
	    PP.RoleID,
	    CASE PP.RoleID
		    when -1 then 'All Users'
		    when -2 then 'Superuser'
		    when -3 then 'Unauthenticated Users'
		    else 	R.RoleName
	    END AS 'RoleName',
	    PP.AllowAccess, 
	    PP.UserID,
	    U.Username,
	    U.DisplayName, 
	    P.PermissionCode, 
	    P.ModuleDefID, 
	    P.PermissionKey, 
	    P.PermissionName,
	PP.CreatedByUserID,
	PP.CreatedOnDate,
	PP.LastModifiedByUserID,
	PP.LastModifiedOnDate
    FROM dbo.DnnProduct_DesktopModulePermission AS PP 
	    LEFT OUTER JOIN dbo.DnnProduct_Permission AS P ON PP.PermissionID = P.PermissionID 
	    LEFT OUTER JOIN dbo.DnnProduct_Roles AS R ON PP.RoleID = R.RoleID
	    LEFT OUTER JOIN dbo.DnnProduct_Users AS U ON PP.UserID = U.UserID
GO
